package com.registration.service.util.handler;

import exception.YyghException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import result.Result;

/**
 * @author 20405
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)//当出现Exception异常时执行当前方法
    @ResponseBody//方法返回为json格式
    public Result error(Exception e){
//        throw new YyghException(e.getMessage(),201);
        e.printStackTrace();
        return Result.fail();
    }
    @ExceptionHandler(YyghException.class)
    @ResponseBody
    public Result error1(YyghException e){
        return Result.build(e.getCode(),e.getMessage());
    }
}
